package com.mijie.homi.dao.commom;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.domain.commom.Reply;

@Repository
public class ReplyDao extends IBatisDao{


	public int postReply(Reply reply){
		return this.insert("postReply", reply);
	}
	
	public List<Reply> listReply(String tableName,long idx,long targetId,int limit){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", tableName);
		parameter.put("idx", idx);
		parameter.put("targetId", targetId);
		parameter.put("limit", limit);
		return this.selectList("listReply", parameter);
	}
	
	public Reply getReplyById(String tableName,long id){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", tableName);
		parameter.put("id", id);
		return this.selectOne("getReplyById", parameter);
	}
	
	public int deleteReply(String tableName,int sender,long id){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", tableName);
		parameter.put("sender", sender);
		parameter.put("id", id);
		return this.delete("deleteReply", parameter);
	}
	
	public int deleteReplyByAdmin(String tableName,int administrator,long id){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", tableName);
		parameter.put("administrator", administrator);
		parameter.put("id", id);
		return this.delete("deleteReplyByAdmin", parameter);
	}
	
	public List<Reply> listReplyByTargetIds(String tableName,long targetId,int limit){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("tableName", tableName);
		parameter.put("targetId", targetId);
		parameter.put("limit", limit);
		return  this.selectList("listReplyByTargetIds", parameter);
	}
}
